package keyboard;

import screen.*;
import command.*;
import misc.*;

public class KeyRecorder {
    private Screen screen;
    private StringBuilder sb = new StringBuilder();
    public KeyRecorder(Screen scr) {
        screen = scr;
    }
    public void add(char c) {
        screen.discard();
        if (c != '\b' && c != '\n') {
            sb.append(new Character(c).toString());
            screen.print(new Character(c).toString());
        } else if (c == '\n') {
            screen.println("");
            sb.append("\n");
        } else {
            if (sb.length() != 0) {
                sb.deleteCharAt(sb.length() - 1);
                screen.discard();
            }
        }
        screen.print("_");
    }
    public void add(String s) {
        char arr[] = s.toCharArray();
        for (char c : arr) add(c);
    }
    public void execute() {
        screen.discard();
        String s = sb.toString();
        CommandExecutor.run(screen, s);
        sb.delete(0, sb.length());
        screen.println(Props.displayPath + "\\>_");
    }
}